package com.youmeek.ssm.module.user.controller;

import com.youmeek.ssm.module.user.pojo.Goods;
import com.youmeek.ssm.module.user.pojo.Page;
import com.youmeek.ssm.module.user.service.impl.GoodsService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

/**
 * 作者  Administrator
 * 时间  2017/7/12 9:48
 * 文件  ssm
 * 描述  商品控制层
 */
@Controller
@RequestMapping("/goods")
public class GoodsController extends BaseAction {

	@Resource
	private GoodsService goodsService;

	@RequestMapping("/selectPage")
	@ResponseBody
	public Object selectPage(Page<Goods> page,Goods goods){
		page.setParamsEntity(goods);
		Page<Goods> origin = goodsService.selectGoods(page);

		Map<String,Object> result = new HashMap<>();
		result.put("total",origin.getTotal());
		result.put("rows",origin.getList());
		return result;
	}

	@RequestMapping("/updata")
	public void updata(Goods goods){

	}

	@RequestMapping("/deleteByPks")
	public void deleteByPks(String[] pks){

	}

	@RequestMapping("/insertGoods")
	@ResponseBody
	public int inserGoods(Goods goods){
		int i = 0;
		try {
			i = goodsService.insertSelective(goods);
		}catch (Exception e){
			e.printStackTrace();
		}
		return i;
	}

}
